#include "ccallanswerer.h"
#include <w32std.h>
#include <QDebug>

CCallAnswerer::CCallAnswerer(MAnswerObserver& aObserver, CTelephony* aTelephony)
    : CActive(EPriorityStandard)
    ,iObserver(aObserver)
    ,iTelephony(aTelephony)
{
    CActiveScheduler::Add( this );
}

CCallAnswerer::~CCallAnswerer() {
    Cancel();
}

void CCallAnswerer::Answer() {
    iTelephony->AnswerIncomingCall(iStatus, iCallId);    
    SetActive();
}

void CCallAnswerer::RunL()
{
    if(iStatus==KErrNone){
        qDebug() << "[CCallAnswerer::RunL()] chiamata risposta correttamente";
       iObserver.CallAnsweredL( iStatus.Int() );
    } else {
        qDebug() << "[CCallAnswerer::RunL()] errore: "<< QString::number(iStatus.Int());
    }    
}

void CCallAnswerer::DoCancel()
{
    iTelephony->CancelAsync(CTelephony::EAnswerIncomingCallCancel);
}
